package com.zf.zffencheng.model;

import com.zf.zffencheng.exception.Error_;
import com.zf.zffencheng.exception.ResultException;
import lombok.Data;

/**
 * ClassName: Result <br/>
 * Description:  <br/>
 * date: 2021/5/8 16:29<br/>
 *
 * @author william <br/>
 */
@Data
public class Result {
    private int code = 0;
    private String msg = "ok";
    private Object data;
    private Long timestamp = System.currentTimeMillis();
    public static Result ok(){
        return new Result();
    }

    public static Result ok(Object data){
        Result result = new Result();
        result.setData(data);
        return result;
    }

    public static Result error(int code, String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result error(Error_ dataEmpty) {
        Result result = new Result();
        result.setCode(dataEmpty.getCode());
        result.setMsg(dataEmpty.getMsg());
        return result;
    }

    public static Result error(ResultException e) {
        Result result = new Result();
        result.setCode(e.getCode());
        result.setMsg(e.getMsg());
        return result;
    }

    public static Result error(String error) {
        Result result = new Result();
        result.setCode(9999);
        result.setMsg(error);
        return result;
    }
}
